﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MODEL;
using SysHelper;
using MarketplaceWebService.Model;
using System.IO;

namespace SysController
{
    /// <summary>
    /// 调度控制器
    /// </summary>
    internal static class InvokeController 
    {
        /*================================ 
        报告调度
          
        1：卖家提交一个 RequestReport  操作
        2：亚马逊收到请求 返回 ReportRequestId 
        3: 卖家提交一个 GetRePortRequestList 操作
        4：亚马逊返回处理状态，为 '_DONE_' 时有些报告会返回 GeneratedReportId
        5: 报告是否生成
        6：是否有 GeneratedReportId 返回
         * 6.1 （是） 卖家提交一个 GetReport 操作，参数 为  GeneratedReportId 或 ReportId
         * 6.2  (否） 卖家提交一个 GetReportList 操作使用 ReportRequestId 为参数来 获取 ReportId
         * 6.2   同6.1 
         * =================================*/



        /*-------------------------CategoryInfo Invoke-----------------------------------------*/


















        #region 2.0  请求报告 请求实体 + RequestReportRequest RequestReport(UP_GetMwsModel_Result Result, ReportTypeEnum ReportType)
        /// <summary>
        /// 2.0  请求报告 请求实体
        /// </summary>
        /// <param name="Result">商城信息</param>
        /// <param name="ReportType">报告类型</param>
        /// <returns>请求报告实体</returns>
        public static RequestReportRequest RequestReport(UP_GetMwsModel_Result Result, ReportTypeEnum ReportType)
        {
            RequestReportRequest Request = new RequestReportRequest();
            Request.MarketplaceIdList = new IdList();
            Request.MarketplaceIdList.Id = new List<string>(new string[] { Result.MarketplaceCode });
            Request.Merchant = Result.MerchantCode;
            Request.ReportType = ReportType.ToString();
            //Request.ReportOptions = ReportType.ToString(); 
            //Request.StartDate = DateTime.Now;
            //Request.EndDate = DateTime.Now; 
            return Request;
        }
        #endregion

        public static GetReportRequestListRequest GetReportRequestList(UP_GetMwsModel_Result Result, ReportTypeEnum ReportType)
        {
            GetReportRequestListRequest Request = new GetReportRequestListRequest();
            Request.Merchant = Result.MerchantCode;
            Request.ReportTypeList = new TypeList();
            Request.ReportTypeList.Type = new List<string>(new string[] { ReportType.ToString() });
            Request.ReportRequestIdList = new IdList();
            Request.ReportRequestIdList.Id = new List<string>(new string[] { });
            return Request;
        }

        public static GetReportListRequest GetReportList(UP_GetMwsModel_Result Result, List<MODEL.ReportRequestInfo> list, ReportTypeEnum ReportType)
        {
            List<string> listId = new List<string>();
            foreach (var item in list)
            {
                listId.Add(item.ReportRequestInfo_Id);
            }
            GetReportListRequest Request = new GetReportListRequest();
            Request.Merchant = Result.MerchantCode;
            Request.ReportRequestIdList = new IdList();
            Request.ReportRequestIdList.Id = listId;

            return Request;
        }

        public static GetReportRequest GetReport(UP_GetMwsModel_Result Result)
        {
            GetReportRequest Request = new GetReportRequest();
            Request.Merchant = Result.MerchantCode;
            Request.ReportId = "76750642016645";
            Request.Report = File.Open("report.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            return Request;
        }
    }
}
